<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
		"http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<title>doh.robot Calendar A11Y Test</title>

		<style>
			@import "../../../util/doh/robot/robot.css";
		</style>

		<!-- required: dojo.js -->
		<script type="text/javascript" src="../../../dojo/dojo.js"
			djConfig="isDebug: true"></script>

		<!-- functions to help test -->
		<script type="text/javascript" src="../helpers.js"></script>

		<script type="text/javascript">
			dojo.require("dijit.dijit"); // optimize: load dijit layer
			dojo.require("dijit.robotx");
			dojo.require("dojo.date");

			dojo.addOnLoad(function(){
				doh.robot.initRobot('../test_Calendar.html');

				// refs to Calendar widget
				var cal1;

				// log of calls to onChange handler
				var changes = [];

				doh.register("dijit.Calendar keyboard tests",[
					{
						name: "arrow navigation",
						timeout: 10000,
						setUp: function(){
							// refs to Calendar widget
					    	cal1 = dijit.byId('calendar1');
							cal1.attr("value", new Date(2009, 8, 16));

					    	// setup onChange handler to monitor onChange calls on cal1
							dojo.connect(cal1, 'onChange', function(val){
								console.log('onchange w/value: ', val);
								changes.push(val);
							});
						},
						runTest: function(){
							var d = new doh.Deferred();
							doh.robot.sequence(function(){
								// monitor onchange events
								changes = [];
								cal1.domNode.focus();
							}, 500);

							doh.robot.keyPress(dojo.keys.RIGHT_ARROW, 500, {});
							doh.robot.keyPress(dojo.keys.RIGHT_ARROW, 500, {});
							doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500, {});
							doh.robot.keyPress(dojo.keys.LEFT_ARROW, 500, {});
							doh.robot.keyPress(dojo.keys.UP_ARROW, 500, {});
							doh.robot.keyPress(dojo.keys.UP_ARROW, 500, {});
							doh.robot.sequence(d.getTestCallback(dojo.hitch(this, function(){
								var value = cal1.attr('value');
								doh.is(0, dojo.date.compare(new Date(2009, 8, 10), value), 'actual value is ' + value);
								doh.is(6, changes.length, 'six onchange events');
								doh.is(0, dojo.date.compare(new Date(2009, 8, 17), changes[0]),
										'value reported by onchange: ' + changes[0] +
										', should be ' + new Date(2009, 8, 17));
							})), 1000);
							return d;
						}
					},
					{
						name: "month navigation",
						timeout: 5000,
						setUp: function(){
							// refs to Calendar widget
					    	cal1 = dijit.byId('calendar1');
							cal1.attr("value", new Date(2008, 0, 31));
						},
						runTest: function(){
							var d = new doh.Deferred();
							doh.robot.sequence(function(){
								// monitor onchange events
								cal1.domNode.focus();
							}, 500);

							doh.robot.keyPress(dojo.keys.PAGE_DOWN, 500, {});
							doh.robot.sequence(d.getTestCallback(dojo.hitch(this, function(){
								var value = cal1.attr('value');
								doh.is(0, dojo.date.compare(new Date(2008, 1, 29), value), 'actual value is ' + value);
							})), 1000);
							return d;
						}
					},
					{
						name: "month+year navigation",
						timeout: 5000,
						setUp: function(){
							// refs to Calendar widget
					    	cal1 = dijit.byId('calendar1');
							cal1.attr("value", new Date(2008, 1, 15));
						},
						runTest: function(){
							var d = new doh.Deferred();
							doh.robot.sequence(function(){
								// monitor onchange events
								cal1.domNode.focus();
							}, 500);

							doh.robot.keyPress(dojo.keys.END, 500, {});
							doh.robot.keyPress(dojo.keys.PAGE_DOWN, 500, {ctrl:true});
							doh.robot.keyPress(dojo.keys.PAGE_UP, 500, {ctrl:true});
							doh.robot.keyPress(dojo.keys.PAGE_UP, 500, {ctrl:true});
							doh.robot.sequence(d.getTestCallback(dojo.hitch(this, function(){
								var value = cal1.attr('value');
								doh.is(0, dojo.date.compare(new Date(2007, 1, 28), value), 'actual value is ' + value);
							})), 1000);
							return d;
						}
					}
				]);

				doh.run();
			});
		</script>
	</head>
</html>
